//package com.daxt.utils;
//
//import com.itextpdf.io.font.FontConstants;
//import com.itextpdf.kernel.color.Color;
//import com.itextpdf.kernel.font.PdfFont;
//import com.itextpdf.kernel.font.PdfFontFactory;
//import com.itextpdf.kernel.geom.AffineTransform;
//import com.itextpdf.kernel.geom.Rectangle;
//import com.itextpdf.kernel.pdf.*;
//import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
//import com.itextpdf.kernel.pdf.annot.PdfAnnotationAppearance;
//import com.itextpdf.kernel.pdf.annot.PdfFixedPrint;
//import com.itextpdf.kernel.pdf.annot.PdfWatermarkAnnotation;
//import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
//import com.itextpdf.kernel.pdf.extgstate.PdfExtGState;
//import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
//import com.itextpdf.text.pdf.PdfCopy;
//
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//
//
//public class WaterMarkUtil7 {
//	private static int interval = -5;
//
//	public static void main(String[] args){
//        try {
//            watermarkPDF("C:\\Users\\Administrator\\Desktop\\a001.pdf","D:\\a\\1447475314996285441.pdf");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//
//    public static void watermarkPDF(String sourceFile, String destinationPath) throws IOException {
//
////        Document document = new Document();
////        PdfCopy copy = new PdfCopy(document, new FileOutputStream(sourceFile)); //输出pdf文件;
////        document.open();
////
////
////        byte[] b= new byte[file.available()]; ///这里是解决问题的重点
////        int len=0;
////        while((len=file.read(b))>0){undefined
////
////            file.read(b,0,b.length);///这里是解决问题的重点
////
////            PdfReader pdfr=new PdfReader(new PdfReader(b));///这里是解决问题的重点
////
////            int num=pdfr.getNumberOfPages();
////            System.out.println("第一次页数是:"+num);
////            if(num<end||begin<0||begin>end){undefined
////                System.out.println("截取的页数不正确!");
////            }else {
////                for(int i=begin;i<=end;i++){undefined
////                    document.newPage();
////                    PdfImportedPage page=copy.getImportedPage(pdfr, i);
////                    copy.addPage(page);
////                }
////            }
////        }
////        document.close();
//
//
//        float watermarkTrimmingRectangleWidth = 300;
//        float watermarkTrimmingRectangleHeight = 300;
//
//        float formWidth = 300;
//        float formHeight = 300;
//        float formXOffset = 0;
//        float formYOffset = 0;
//
//        float xTranslation = 50;
//        float yTranslation = 25;
//
//        double rotationInRads = Math.PI/3;
//
//        PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
//        float fontSize = 50;
//
//        PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFile), new PdfWriter(destinationPath));
////        int numberOfPages = pdfDoc.getNumberOfPages();
////        PdfPage page = null;
////
////        for (int i = 1; i <= numberOfPages; i++)
////        {
////            System.err.println("22222222222:"+i);
////            System.err.println("pdfDoc  pages:"+pdfDoc.getNumberOfPages());
////            page = pdfDoc.getPage(i);
////            Rectangle ps = page.getPageSize();
////
////            //Center the annotation
////            float bottomLeftX = ps.getWidth()/2 - watermarkTrimmingRectangleWidth/2;
////            float bottomLeftY = ps.getHeight()/2 - watermarkTrimmingRectangleHeight/2;
////            Rectangle watermarkTrimmingRectangle = new Rectangle(bottomLeftX, bottomLeftY, watermarkTrimmingRectangleWidth, watermarkTrimmingRectangleHeight);
////
////            PdfWatermarkAnnotation watermark = new PdfWatermarkAnnotation(watermarkTrimmingRectangle);
////
////            //Apply linear algebra rotation math
////            //Create identity matrix
////            AffineTransform transform = new AffineTransform();//No-args constructor creates the identity transform
////            //Apply translation
////            transform.translate(xTranslation, yTranslation);
////            //Apply rotation
////            transform.rotate(rotationInRads);
////
////            PdfFixedPrint fixedPrint = new PdfFixedPrint();
////            watermark.setFixedPrint(fixedPrint);
////            //Create appearance
////            Rectangle formRectangle = new Rectangle(formXOffset, formYOffset, formWidth, formHeight);
////
////            //Observation: font XObject will be resized to fit inside the watermark rectangle
////            PdfFormXObject form = new PdfFormXObject(formRectangle);
////            PdfExtGState gs1 = new PdfExtGState().setFillOpacity(0.6f);
////            PdfCanvas canvas = new PdfCanvas(form, pdfDoc);
////
////            float[] transformValues = new float[6];
////            transform.getMatrix(transformValues);
////            canvas.saveState()
////                    .beginText().setColor(Color.GRAY, true).setExtGState(gs1)
////                    .setTextMatrix(transformValues[0], transformValues[1], transformValues[2], transformValues[3], transformValues[4], transformValues[5])
////                    .setFontAndSize(font, fontSize)
////                    .showText("watermark text")
////                    .endText()
////                    .restoreState();
////
////            canvas.release();
////
////            watermark.setAppearance(PdfName.N, new PdfAnnotationAppearance(form.getPdfObject()));
////            watermark.setFlags(PdfAnnotation.PRINT);
////
////            page.addAnnotation(watermark);
////
////        }
////        page.flush();
//        pdfDoc.close();
//    }
//
//
//}
